package com.woniuxy.controller;

import com.woniuxy.entity.Game;
import com.woniuxy.service.impl.ManagerServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Manager")
public class ManagerController {
    ManagerServiceImpl ManagerService;
    @RequestMapping("/findAll")
    public String findAll(Model model, ModelMap modelMap, HttpServletRequest request, HttpServletResponse response, HttpSession httpSession) throws ServletException, IOException {
        List<Game> managers = ManagerService.findAll();
        model.addAttribute("data",managers);
        return "success";
    }
    @RequestMapping("/findByName")
    public String findByName(@RequestParam("name") String username, Model model){
        List<Game> list = ManagerService.findByName(username);
        model.addAttribute("data",list);
        return "success";
    }
    @RequestMapping(value = "/findByIds",method = RequestMethod.POST)
    public String findByIds(Integer[] ids, Model model){
        List<Game> list = ManagerService.findByIds(ids);
        model.addAttribute("data",list);
        return "success";
    }
    @RequestMapping(value = "/findByLists",method = RequestMethod.POST)
    public String findByLists(@RequestParam List<Integer> ids, Model model){
        Integer[] objects = ids.toArray(new Integer[0]);
        List<Game> list = ManagerService.findByIds(objects);
        model.addAttribute("data",list);
        return "success";
    }
    @RequestMapping(value = "/addOneForMap")
    public String addOneForMap(@RequestParam Map<String,Object> userinfo, Model model){
        if (userinfo.size()!=0) {
            int i = ManagerService.addOneForMap(userinfo);
        }
        model.addAttribute("data","新增："+userinfo);
        return "success";
    }
    @RequestMapping("/addOne")
    public String addOne(ManagerServiceImpl Manager,Model model){
        int i = ManagerService.addOne(Manager);
        model.addAttribute("data","新增："+Manager);
        return "success";
    }
}
